import { createRouter, createWebHistory } from 'vue-router'
//createRouter ： 创建路由实例
//createWebHistory ： 创建基于浏览器 history API 的路由历史记录
import Layout from '@/views/layout/Index.vue'
import Login from '@/views/login/Index.vue'
import Home from '@/views/home/Index.vue'
import Category from '@/views/category/Index.vue'
import SubCategory from '@/views/subCategory/Index.vue'
import Detail from '@/views/detail/Index.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/Checkout/index.vue'
import Pay from '@/views/pay/index.vue'
import PayOver from "@/views/Pay/payOver.vue";
import Member from "@/views/member/Index.vue";
import UserInfo from "@/views/Member/components/UserInfo.vue";
import UserOrder from "@/views/Member/components/UserOrder.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: Layout,
      children:[
        {
          path: '',//默认路径
          component: Home,
        },
        {
          path: 'category/:id',//表示当用户访问类似 category/123 的URL时，Vue Router会渲染 Category 组件，并将 123 作为参数传递给该组件。这在实际应用中通常用于展示特定类别的商品或内容。
          component: Category,
        },
        {
          path: 'category/sub/:id',//表示当用户访问类似 category/123 的URL时，Vue Router会渲染 Category 组件，并将 123 作为参数传递给该组件。这在实际应用中通常用于展示特定类别的商品或内容。
          component: SubCategory,
        },
        {
          path: 'detail/:id',
          component: Detail,
        },
        {
          path: 'cartList',
          component: CartList,
        },
        {
          path: 'checkout',
          component: CheckOut,
        },{
          path:'pay',
          component: Pay,
        },{
          path:'paycallback',
          component: PayOver
        },{
          path:'member',
          component: Member,
          redirect: "/member/user",
          children: [
            {
              path: 'user',
              component: UserInfo,
            },
            {
              path: 'order',
              component: UserOrder,
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      component: Login,
    }
  ],
  scrollBehavior(){ //切换路由时页面滚动到顶部
    return { top: 0 }
  }
})

export default router
